package com.codemonkey.lq.common.operators;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

class PropsFileOperater {
    final String filePath;
    final Properties props;

    public PropsFileOperater(String filePath) {
        super();

        this.filePath = filePath;
        this.props = new Properties();

        loadConfigFile();
    }

    private void loadConfigFile() {
        String path = this.getClass().getClassLoader().getResource(filePath).getPath();
        InputStream is = null;
        try {
            // 
            // 每次执行强制加载最新的文件
            is = new FileInputStream(path);
            // 强制指定编码格式
            // InputStreamReader is = new
            // InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(filePath),"UTF-8");
            props.load(is);
        }
        catch (IOException e1) {
            e1.printStackTrace();
        }
        finally {
            if (null != is) {
                try {
                    is.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
